import java.util.Stack;

class MyQueue {
    private Stack<Integer> stack1 ;
    private Stack<Integer> stack2 ;
    public MyQueue() {
        this.stack1 = new Stack<>() ;
        this.stack2 = new Stack<>() ;

    }

    public void push(int x) {
        stack1.push(x) ;
    }

    public int pop() {
        int ret = 0 ;
        if(!stack1.empty()){
            while(!stack1.empty()){
                ret = stack1.pop() ;
                stack2.push(ret) ;
            }
            ret = stack2.pop() ;
            while(!stack2.empty()){
                stack1.push(stack2.pop());
            }
        }else{
            while(!stack2.empty()){
                ret = stack2.pop() ;
                stack1.push(ret) ;
            }
            ret = stack1.pop() ;
            while(!stack1.empty()){
                stack2.push(stack1.pop());
            }
        }
        return ret ;
    }

    public int peek() {
        int ret = 0 ;
        if(!stack1.empty()){
            while(!stack1.empty()){
                ret = stack1.pop() ;
                stack2.push(ret) ;
            }
            while(!stack2.empty()){
                stack1.push(stack2.pop());
            }
        }else{
            while(!stack2.empty()){
                ret = stack2.pop() ;
                stack1.push(ret) ;
            }
            while(!stack1.empty()){
                stack2.push(stack1.pop());
            }
        }
        return ret ;
    }

    public boolean empty() {
        return stack1.empty() && stack2.empty() ;
    }
}

/**
 * Your MyQueue object will be instantiated and called as such:
 * MyQueue obj = new MyQueue();
 * obj.push(x);
 * int param_2 = obj.pop();
 * int param_3 = obj.peek();
 * boolean param_4 = obj.empty();
 */